package com.gthncz;

import java.util.*;

public class Demo12 {

    public static void main(String[] args) {
        int n, m;
        ArrayList<ArrayList<Integer>> groups = new ArrayList<ArrayList<Integer>>();
        Map<Integer, Set<Integer>> p2g = new HashMap<Integer, Set<Integer>>();

        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();

        if (n < 1 || m < 1) {
            System.out.printf("0");
            return;
        }

        boolean[] visited = new boolean[n];

        // 添加 groups
        int x, tmp;
        for (int i = 0; i < m; ++i) {
            x = sc.nextInt();
            ArrayList<Integer> group = new ArrayList<Integer>(x);
            while (x-- > 0) {
                tmp = sc.nextInt();

                if (tmp >= n || tmp < 0) {
                    System.out.printf("0");
                    return;
                }

                group.add(tmp);
                if (!p2g.containsKey(tmp)) {
                    p2g.put(tmp, new HashSet<Integer>());
                }
                p2g.get(tmp).add(i);
            }
            groups.add(group);
        }

        // 初始化
        Deque<Integer> queue = new ArrayDeque<Integer>();
        int result = 0;

        queue.offer(0);
        visited[0] = true;
        while (!queue.isEmpty()) {
            int p = queue.poll();
            ++result;

            if (p2g.containsKey(p)) {
                Set<Integer> g = p2g.get(p);
                for (int i : g) {
                    ArrayList<Integer> group = groups.get(i);
                    for (int pog : group) {
                        if (!visited[pog]) {
                            queue.offer(pog);
                            visited[pog] = true;
                        }
                    }
                }
            }
        }

        System.out.printf("%d", result);
    }
}